import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'element-plus/dist/index.css'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createPinia } from 'pinia'
const pinia = createPinia()
//时间转换标准时间
import moment from 'moment'
// 引入图片预览
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'

router.beforeEach((to, from) => {
    const token = localStorage.getItem('Authorization')
    if (!token && to.path !== '/login') {
        return '/login'
    } else if (token && to.path === '/login') {
        return '/'
    } else {
        return true
    }
})


const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
//全局过滤器(时间转换)
app.config.globalProperties.$filters = {
    //formatData过滤器的名称
    formatDate(value, formatString = 'YYYY-MM-DD HH:mm:ss') {
        return moment(value).format(formatString);
    },
};
app.config.globalProperties.$myFilter = (value) => {
    return value.filters();
};
//挂载图片预览组件
app.use(Viewer, {
    defaultOptions: {
        zIndex: 9999, // 设置图片预览组件的层级，确保能在其他组件之上
    },
})
app.use(pinia)
app.use(ElementPlus)
app.use(store).use(router).mount('#app')
